package com.huiyuanai.pojo.role;

import com.huiyuanai.dao.Role;
import com.huiyuanai.util.BaseUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: liwan
 * @Description:
 * @Date: create in 2021/10/6
 */
public class RolePojoImpl implements RolePojo{

    @Override
    public List<Role> getRoleList(Connection connection) throws SQLException {
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Role> roles = new ArrayList<Role>();

        if (connection != null) {
            String sql = "select * from smbms_role";
            Object[] datas = {};
            resultSet = BaseUtil.execute(connection, sql, datas, resultSet, preparedStatement);
            while (resultSet.next()) {
                Role role = new Role();
                role.setId(resultSet.getInt("id"));
                role.setRoleName(resultSet.getString("roleName"));
                roles.add(role);
            }
        }

        //释放资源
        BaseUtil.clostResour(null, preparedStatement, resultSet);
        return roles;
    }
}
